package com.cskaoyan.processor;

import com.cskaoyan.bean.LifeCycleBean;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @author stone
 * @date 2022/08/27 11:33
 */
public class CustomBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        // 先识别组件是LifeCycleBean组件，设置parameter1为李艮隶
        if (bean instanceof LifeCycleBean) {
            ((LifeCycleBean)bean).setParameter1("李艮隶");
        }

        System.out.println("postProcessBeforeInitialization:" + beanName);
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessAfterInitialization:" + beanName);
        return bean;
    }
}
